﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using EasyNetQ;
using EasyNetQ.Topology;

namespace RabbitMQ_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var exchange = new Exchange("test.topic");
            var publisher = RabbitHutch.CreateBus("host=192.168.7.244:5672;username=lxm;password=lxm");

            for (int i = 0; i < 20; i++)
            {
                try
                {
                    //生产者
                    string time = DateTime.Now.ToString("yyyyMMddHHmmss");
                    var body = Encoding.UTF8.GetBytes(time.ToString());
                    publisher.Advanced.Publish(exchange, "lxm.test", false, new MessageProperties(), body);
                    Console.WriteLine("ok:" + i.ToString());
                    Thread.Sleep(2000);

                    //消费者
                    var queue = publisher.Advanced.QueueDeclare("lxm.queue");
                    var result = publisher.Advanced.Get(queue);
                    Console.WriteLine("result:" + Encoding.UTF8.GetString(result.Body));
                    Thread.Sleep(2000);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            Console.WriteLine("over");
        }
    }
}
